#include "VGCVirtualGameConsole.h"
#include "CGameEntity.h"
#include "CVector.h"
#include "CImage.h"

using namespace std;

CGameEntity::CGameEntity(CImage image, double x, double y, double speed, double direction):
	CImageEntity(image, x, y),
	speed(speed),
	direction(direction),
	lastTime(0) 
	{
		
	}

CGameEntity::~CGameEntity() {}

void CGameEntity::setSpeed(double speed) {
	this->speed = speed;
}

double CGameEntity::getSpeed() {
	return this->speed;
}

void CGameEntity::setDirection(double direction) {
	this->direction = direction;
}

double CGameEntity::getDirection() {
	return this->direction;
}

void CGameEntity::step(const double &time) {
	double d = delta(time);

	double vCos = cos(getDirection());
	double vSin = sin(getDirection());

	setPosition(CVector(
		getPosition().getX() + vCos * getSpeed() * d,
		getPosition().getY() - vSin * getSpeed() * d));
}

double CGameEntity::delta(const double &time) {
	double temp = lastTime;
	lastTime = time;
	return lastTime - temp;
}

bool CGameEntity::isAt(CVector point) {
	return ((point.getX() > getPosition().getX())
		&&  (point.getY() > getPosition().getY())
		&&  (point.getX() < getPosition().getX() + getImage().getFrameWidth())
		&&  (point.getY() < getPosition().getY() + getImage().getFrameHeight()));
}